﻿@model OT.Areas.Admin.Models.Subjects

<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
        <h3 id="myModalLabel">Edit Subject</h3>
    </div>
    <div>
        @Html.HiddenFor(model => model.SubjectID, new { id = "HDFID" })
        <div class="modal-body">
            <div id="alert_modal"></div>
             <div class="form-horizontal" role="form">
                 <div class="form-group">
            <div class="col-lg-16">
                <div id="divMsgEdit"></div>
            </div>
        </div>
                <div class="form-group" id="divCategoryName">
                    <label class="col-lg-3 control-label">Category Name</label>
                    <div class="col-lg-5">
                        @Html.DropDownListFor(model => model.CategoryID, new SelectList(Model.categorys, "CategoryID", "CategoryName"), "--select--", new { @class = "form-control", id = "CategoryID" })
                        @Html.ValidationMessageFor(model => model.CategoryID)
                    </div>
                </div>
                <div class="form-group" id="divSubjectName">
                    <label class="col-lg-3 control-label">Subject Name</label>
                    <div class="col-lg-5">
                         @Html.TextBoxFor(model => model.SubjectName, new { @maxlength = "50",@class="form-control",@placeholder="Enter Subject Name" })
                        @Html.ValidationMessageFor(model => model.SubjectName)
                    </div>
                </div>
                <div class="form-group" id="divDescription">
                    <label class="col-lg-3 control-label">Description</label>
                    <div class="col-lg-5"><textarea class="form-control" placeholder="Enter Description" id="Description" rows="1" maxlength="50">@Model.Description</textarea>
                    </div>
                </div>
               
            </div>
        </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-default" type="submit" id="btnEdit"><i class="icon-cog"></i>Save</button>
            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i>Cancel</button>
        </div>
    </div>

<script type="text/javascript">
    $("#btnEdit").click( function (e) {
        var SubjectID = $("#HDFID").val();
        var CategoryID = $("#CategoryID option:selected").val();
        var SubjectName = $("#SubjectName").val();
        var Description = $("#Description").val();
       
        e.preventDefault();
        if (SubjectName == '' || CategoryID == 0) {
            showMsg('divMsgEdit', 'Please Enter Value For Required Fields', 'danger');
            (CategoryID == 0) ? $('#divCategoryName').addClass('has-error') : $('#divCategoryName').removeClass('has-error');
            (SubjectName == '') ? $('#divSubjectName').addClass('has-error') : $('#divSubjectName').removeClass('has-error');
        }
        else {
            $.ajax({
                url: "/Instructor/Subject/Edit?SubjectID=" + SubjectID + "&SubjectName=" + SubjectName + "&Description=" + Description + "&CategoryID=" + CategoryID ,
                type: "POST",
                success: function (result) {
                    if (result != "NotValid") {
                        $('#modalDiv').modal('hide');
                        showMsg('divMsgIndex', 'Record Updated Successfuly', 'success');
                        loadPage(1, 10, '');
                    }
                    else {
                        showMsg('divMsgEdit', 'Failed To Update', 'danger');
                    }
                },
                error: function (data) {
                }
            });
        }
        return false;
    });
</script>